﻿
// Permite ingresar números enteros mientras el usuario escribe
jQuery.fn.ForceIntegerOnly = function () {
    return this.each(function () {
        $(this).keydown(function (e) {
            var key = e.which || e.keyCode;

            if (!e.shiftKey && !e.altKey && !e.ctrlKey &&
            // numbers   
                     key >= 48 && key <= 57 ||
            // Numeric keypad
                     key >= 96 && key <= 105 ||
            // Backspace and Tab and Enter
                     key == 8 || key == 9 || key == 13 ||
            // Home and End
                     key == 35 || key == 36 ||
            // left and right arrows
                     key == 37 || key == 39 ||
            // Del and Ins
                     key == 46 || key == 45) return true;

            return false;
        });
    });
};
// Permite ingresar números y/o flotantes mientras el usuario escribe
jQuery.fn.ForceFloatOnly = function () {
    return this.each(function () {
        $(this).keydown(function (e) {
            var key = e.which || e.keyCode;

            if (!e.shiftKey && !e.altKey && !e.ctrlKey &&
            // numbers   
                     key >= 48 && key <= 57 ||
            // Numeric keypad
                     key >= 96 && key <= 105 ||
            // comma, period and minus, . on keypad
                     key == 190 || key == 188 || key == 109 || key == 110 ||
            // Backspace and Tab and Enter
                     key == 8 || key == 9 || key == 13 ||
            // Home and End
                     key == 35 || key == 36 ||
            // left and right arrows
                     key == 37 || key == 39 ||
            // Del and Ins
                     key == 46 || key == 45) return true;

            return false;
        });
    });
};
// Impide que se ingresen números mientras se escribe
jQuery.fn.ForceAlphabeticOnly = function () {
    return this.each(function () {
        $(this).keydown(function (e) {
            var key = e.which || e.keyCode;

            if ((e.shiftKey || e.altKey || e.ctrlKey) &&
            // numbers   
                     (key >= 48 && key <= 57 ||
            // Numeric keypad
                     key >= 96 && key <= 107 || key == 111 || 
                     key == 187 || key == 220 || key == 226) ||
                (!e.shiftKey || !e.altKey || !e.ctrlKey) &&
            // numbers   
                     (key >= 48 && key <= 57 ||
            // Numeric keypad
                     key >= 96 && key <= 107 || key == 111 ||
                     key == 187 || key == 220 || key == 226)) return false;

            return true;
        });
    });
};

